package com.qingcheng.controller;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yangjun
 * 2019/7/17
 * 16:10
 */
@Controller
@RequestMapping("/login")
public class LoginController {
    /**
     * 获取用户名
     * @return
     */
    @RequestMapping("/username")
    public Map username(){
        String username= SecurityContextHolder.getContext().getAuthentication().getName();//等到登录账号
        System.out.println("当前登录用户："+username);
        if("anonymousUser".equals(username)){
            username="";
        }
        Map map=new HashMap();
        map.put("username",username);
        return map;
    }
}
